package com.boot.main.config.configDemo;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
// 过滤器配置
//@Configuration
public class FilterConfig {
//    @Bean
//    public FilterRegistrationBean addAnotherFilter(){
//        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
//        filterRegistrationBean.setFilter(new AnotherFilter());
//        filterRegistrationBean.addUrlPatterns("/*");
//        filterRegistrationBean.setOrder(1);
//        return filterRegistrationBean;
//    }

    @Bean
    public FilterRegistrationBean addReqFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        // 注册过滤器
        filterRegistrationBean.setFilter(new ReqFilter());
        // 设置匹配规则
        filterRegistrationBean.addUrlPatterns("/*");
        //  order数越小，优先级越高，越先执行
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }
}
